package com.loong.service.impl;

import com.loong.entity.JobOption;
import com.loong.entity.StudentCountOption;
import com.loong.mapper.ClazzMapper;
import com.loong.mapper.EmpMapper;
import com.loong.mapper.StudentMapper;
import com.loong.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    private EmpMapper empMapper;
    @Autowired
    private StudentMapper studentMapper;
    @Autowired
    private ClazzMapper clazzMapper;

    @Override
    public JobOption getJobData() {
        List<Map<String, Object>> empJobData = empMapper.countEmpJobData();
        List<Object> jobList = empJobData.stream().map(dataMap -> dataMap.get("pos")).collect(Collectors.toList());
        List<Object> dataList = empJobData.stream().map(dataMap -> dataMap.get("total")).collect(Collectors.toList());
        return new JobOption(jobList, dataList);
    }

    @Override
    public List<Map<String, Object>> getGenderData() {
        return empMapper.countEmpGenderData();
    }

    @Override
    public List<Map<String, Object>> getDegreeData() {
        return studentMapper.countDegreeData();
    }

    @Override
    public StudentCountOption getStudentCountData() {
        List<Map<String, Object>> studentCountData = clazzMapper.countStudentData();
        List<Object> clazzList = studentCountData.stream().map(dataMap -> dataMap.get("name")).collect(Collectors.toList());
        List<Object> dataList = studentCountData.stream().map(dataMap -> dataMap.get("total")).collect(Collectors.toList());
        return new StudentCountOption(clazzList, dataList);
    }
}
